package com.example.homeworkmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.homeworkmanagement.pojo.Administrator;
import com.example.homeworkmanagement.mapper.AdministratorMapper;
import com.example.homeworkmanagement.service.AdministratorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.homeworkmanagement.vo.ResultVO;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 拒绝加班
 * @since 2025-05-25
 */
@Service
public class AdministratorServiceImpl extends ServiceImpl<AdministratorMapper, Administrator> implements AdministratorService {
    @Override
    public ResultVO<Administrator> login(String account, String password) throws Exception {
        QueryWrapper<Administrator> qw = new QueryWrapper<>();
        qw.eq("account", account);
        // 获取一个
        Administrator administrator = this.getOne(qw);

        if (administrator != null) {
            if (administrator.getPassword().equals(password)) {
                // 返回用户信息和角色信息
                return ResultVO.success("登录成功", administrator);
            } else {
                return ResultVO.fail("密码错误");
            }
        }
        return ResultVO.fail("账号不存在");
    }
}
